# -*- coding: utf-8 -*-
#
from .helpers import _s40, _s8, _s4, _z
from ..helpers import untangle


class RabinowitzRichter(object):
    '''
    Philip Rabinowitz and Nira Richter,
    Perfectly Symmetric Two-Dimensional Integration Formulas with Minimal
    Numbers of Points,
    Mathematics of Computation, Vol. 23, No. 108 (Oct., 1969), pp. 765-779,
    <https://doi.org/10.2307/2004962>.
    '''
    def __init__(self, index):
        self.name = 'RabinowitzRichter({})'.format(index)
        if index == 1:
            self.degree = 9
            data = [
                (.1237222328857347e+00, _s40(1.538189001320852)),
                (.6544984694978697e-01, _s4(1.224744871391589)),
                (.5935280476180875e+00, _s4(0.4817165220011443)),
                (.1349017971918148e-02, _s8(2.607349811958554, 0.9663217712794149)),
                ]
        elif index == 2:
            self.degree = 11
            data = [
                (.8176645817675417e-3, _s40(2.757816396257008)),
                (.4363323129985824e-1, _s40(1.732050807568877)),
                (.5373255214498174e+0, _s40(0.6280515301597559)),
                (.3636102608321520e-2, _s8(1.224744871391589, 2.121320343559643)),
                (.9817477042468103e-1, _s8(0.7071067811865475, 1.224744871391589)),
                ]
        elif index == 3:
            self.degree = 11
            data = [
                (.4106569066965604e-3, _s40(2.907364117106118)),
                (.9065690889492120e-1, _s40(1.528230917660483)),
                (.5266955729327722e+0, _s40(0.6178819071436261)),
                (.9681125175723808e-3, _s4(1.904162039910276)),
                (.1515812331366514e+0, _s4(0.9724173472297303)),
                (.7542839504417270e-2, _s8(2.061552812808830, 0.8660254037844387)),
                ]
        elif index == 4:
            self.degree = 13
            data = [
                (-.7482913219380363e+0, _z()),
                (+.3521509661098668e-2, _s40(2.403151765001966)),
                (+.1650055872539264e+0, _s40(1.298479973315986)),
                (+.8537825937946404e-3, _s4(1.912428205769905)),
                (+.1326938806789336e+0, _s4(0.9478854439698223)),
                (+.6447719928481539e+0, _s4(0.3188824732576547)),
                (+.1799266413507747e-4, _s8(3.325657829663178, 1.145527285699371)),
                (+.1279412775888998e-1, _s8(1.882228401823884, 0.8826073082889659)),
                ]
        else:
            assert index == 5
            self.degree = 15
            data = [
                (.8006483569659628e-5, _s40(3.538388728121807)),
                (.3604577420838264e-2, _s40(2.359676416877929)),
                (.1187609330759137e+0, _s40(1.312801844620926)),
                (.4372488543791402e+0, _s40(0.5389559482114205)),
                (.3671735075832989e-4, _s4(2.300279949805658)),
                (.5654866776461627e-2, _s4(1.581138830084189)),
                (.1777774268424240e+0, _s4(0.8418504335819279)),
                (.2735449647853290e-3, _s8(2.685533581755341, 1.112384431771456)),
                (.2087984556938594e-1, _s8(1.740847514397403, 0.7210826504868960)),
                ]

        self.points, self.weights = untangle(data)
        return
